# -*- shell-script -*-

# 41rtas_serv_config - Check which firmware image was booted.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2005

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 41ibm_serv_config,v 1.1 2006/04/11 18:38:28 emunson Exp $

lsmcode_serv_config=$(type -p serv_config)

[ -n "$lsmcode_serv_config" ] || return 0

######################################################################

lsmcode_current_firmware_file="${db_bus_dt_dir}/lsvpd,current-flash-image"

lsmcode_get_current_firmware ()
{
    # Sets: lsmcode_current_firmware
    lsmcode_current_firmware="b"

    if [ -r "$lsmcode_current_firmware_file" ] ; then
	local t
	read t <"$lsmcode_current_firmware_file"

	case "$t" in
	    (0) lsmcode_current_firmware="p" ;;
	    (1) lsmcode_current_firmware="t" ;;
	esac
    fi
}

dynamic_vpd_hooks="${dynamic_vpd_hooks} lsmcode_serv_config"

lsmcode_serv_config ()
{
    if can_cache_vpd ; then
	local cmd="$lsmcode_serv_config -e sp-current-flash-image"
	debug_cmd $cmd >"$lsmcode_current_firmware_file" || \
	    rm -f "$lsmcode_current_firmware_file"
    fi
}
